package com.milorad.ads.pages.admin;

import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextArea;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.spring.injection.annot.SpringBean;

import com.milorad.ads.data.dao.interfaces.CategoryDao;
import com.milorad.ads.data.domain.Category;
import com.milorad.ads.pages.BasePage;

public class CreateEditCategoryPage extends BasePage {
		
	@SpringBean
	private CategoryDao categoryDao;
	
	public CreateEditCategoryPage(Category category) {				
		
		Form<Category> form = new Form<Category>("addCategoryForm", new CompoundPropertyModel<Category>(category)) {

			private static final long serialVersionUID = 1L;

			@Override
			protected void onSubmit() {				
				
				Category category = getModelObject();								
				
				categoryDao.save(category);
				
				setResponsePage(CategoriesAdministrationPage.class);
			}			
		};
		
		form.add(new TextField<Category>("name").setRequired(true));
		form.add(new TextArea<Category>("description").setRequired(true));
		
		add(form);	
		
		add (new BookmarkablePageLink<Void>("adminPanelLink", MainAdminPage.class));
		add (new BookmarkablePageLink<Void>("categoriesAdministrationLink", CategoriesAdministrationPage.class));
	}
}